package com.asdc.demo.exchage;

import com.asdc.demo.utils.RabbitMqUtils;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

/**
 * @ClassName EmitLog
 * @Author bsy
 * @Description 交换机模式
 * @Date 2022/3/13 20:48
 * @Version 1.0
 */
public class EmitLogDir {
    private static final String EXCHANGE_NAME = "logs_dir";

    public static void main(String[] argv) throws Exception {
       /* Channel channel = RabbitMqUtils.getChannel();
        //创建多个 bindingKey
        Map<String, String> bindingKeyMap = new HashMap<>();
        bindingKeyMap.put("info","普通 info 信息");
        bindingKeyMap.put("warning","警告 warning 信息");
        bindingKeyMap.put("error","错误 error 信息");
        //debug 没有消费这接收这个消息 所有就丢失了
        bindingKeyMap.put("debug","调试 debug 信息");
        for (Map.Entry<String, String> entry : bindingKeyMap.entrySet()) {
            String key = entry.getKey();
            String value = entry.getValue();
            channel.basicPublish(EXCHANGE_NAME, key, null, value.getBytes("UTF-8"));
            System.out.println("生产者发出消息" + value);
        }*/

        Channel channel = RabbitMqUtils.getChannel();
        channel.exchangeDeclare(EXCHANGE_NAME, BuiltinExchangeType.DIRECT);
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入信息");
        while (sc.hasNext()) {
            String message = sc.nextLine();
            //channel.basicPublish(EXCHANGE_NAME, "info", null, message.getBytes("UTF-8"));
            channel.basicPublish(EXCHANGE_NAME, "error", null, message.getBytes("UTF-8"));
            System.out.println("生产者发出消息" + message);
        }
    }
}